<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--<el-form-item label="会员号" prop="userNo">
        <el-input
          v-model="queryParams.userNo"
          placeholder="请输入会员号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分组id" prop="groupId">
        <el-input
          v-model="queryParams.groupId"
          placeholder="请输入分组id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="头像" prop="avatar">
        <el-input
          v-model="queryParams.avatar"
          placeholder="请输入头像"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="微信open_id" prop="openId">
        <el-input
          v-model="queryParams.openId"
          placeholder="请输入微信open_id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="idcard">
        <el-input
          v-model="queryParams.idcard"
          placeholder="请输入证件号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="等级id" prop="gradeId">
        <el-input
          v-model="queryParams.gradeId"
          placeholder="请输入等级id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会员开始时间" prop="startTime">
        <el-date-picker clearable
          v-model="queryParams.startTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择会员开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="会员结束时间" prop="endTime">
        <el-date-picker clearable
          v-model="queryParams.endTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择会员结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="余额" prop="balance">
        <el-input
          v-model="queryParams.balance"
          placeholder="请输入余额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="积分" prop="point">
        <el-input
          v-model="queryParams.point"
          placeholder="请输入积分"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生日期" prop="birthday">
        <el-input
          v-model="queryParams.birthday"
          placeholder="请输入出生日期"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号" prop="carNo">
        <el-input
          v-model="queryParams.carNo"
          placeholder="请输入车牌号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源渠道" prop="source">
        <el-input
          v-model="queryParams.source"
          placeholder="请输入来源渠道"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input
          v-model="queryParams.password"
          placeholder="请输入密码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="salt" prop="salt">
        <el-input
          v-model="queryParams.salt"
          placeholder="请输入salt"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属商户id" prop="merchantId">
        <el-input
          v-model="queryParams.merchantId"
          placeholder="请输入所属商户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属店铺id" prop="storeId">
        <el-input
          v-model="queryParams.storeId"
          placeholder="请输入所属店铺id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否员工" prop="isStaff">
        <el-input
          v-model="queryParams.isStaff"
          placeholder="请输入是否员工"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注信息" prop="description">
        <el-input
          v-model="queryParams.description"
          placeholder="请输入备注信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最后操作人" prop="operator">
        <el-input
          v-model="queryParams.operator"
          placeholder="请输入最后操作人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['backendApi:member:add']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['backendApi:member:edit']"
        >修改</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['backendApi:member:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['backendApi:member:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="memberList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <!-- <el-table-column label="头像" align="center" prop="avatar" /> -->
      <el-table-column label="姓名" align="center" prop="name" />
      <!-- <el-table-column label="等级id" align="center" prop="gradeId" /> -->
      <el-table-column label="手机号" align="center" prop="mobile" :show-overflow-tooltip="true"/>
      <!-- <el-table-column label="会员号" align="center" prop="userNo" /> -->

      <el-table-column label="余额" align="center" prop="balance" :show-overflow-tooltip="true">
        
        <!-- <template slot-scope="scope">

          <div v-for="(line, index) in multiLineData" :key="index" aria-describedby="descriptionText">
          {{ line }}
          </div> 
        
        </template> -->
      </el-table-column>
      
       
    

      <!-- <el-table-column label="积分" align="center" prop="point" /> -->
      
      <el-table-column label="状态" align="center" prop="status" />
      <!-- <el-table-column label="性别 1男；0女" align="center" prop="sex" /> -->
      <!-- <el-table-column label="会员id" align="center" prop="id" />
      <el-table-column label="分组id" align="center" prop="groupId" />
      <el-table-column label="微信open_id" align="center" prop="openId" />
      <el-table-column label="证件号码" align="center" prop="idcard" />
      <el-table-column label="会员开始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会员结束时间" align="center" prop="endTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      
      
      <el-table-column label="出生日期" align="center" prop="birthday" />
      <el-table-column label="车牌号" align="center" prop="carNo" />
      <el-table-column label="来源渠道" align="center" prop="source" />
      <el-table-column label="密码" align="center" prop="password" />
      <el-table-column label="salt" align="center" prop="salt" />
      <el-table-column label="地址" align="center" prop="address" />
      <el-table-column label="所属商户id" align="center" prop="merchantId" />
      <el-table-column label="所属店铺id" align="center" prop="storeId" />
      <el-table-column label="是否员工" align="center" prop="isStaff" />
     
      <el-table-column label="备注信息" align="center" prop="description" />
      <el-table-column label="最后操作人" align="center" prop="operator" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['backendApi:member:edit']"
          >扣卡消费</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['backendApi:member:edit']"
          >充值/充次</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-hasPermi="['backendApi:member:edit']"
            disabled
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['backendApi:member:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会员个人信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row :gutter="20">
            <el-col :span="10">
              <el-form-item label="姓名" prop="name">
                <el-input v-model="form.name" placeholder="请输入姓名" disabled/>
              </el-form-item>
            </el-col> 
            <el-col :span="10">
              <el-form-item label="手机号码" prop="mobile">
                <el-input v-model="form.mobile" placeholder="请输入手机号码" disabled/>
              </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="10">
              <el-form-item label="出生日期" prop="birthday">
                <el-date-picker v-model="form.birthday" format="yyyy-MM-dd" value-format="yyyy-MM-dd" disabled
                  :style="{width: '100%'}" 
                  placeholder="请选择日期选择" clearable>
                </el-date-picker>
                <!-- <el-input v-model="form.birthday" placeholder="请输入出生日期" /> -->
              </el-form-item>
            </el-col> 
            <el-col :span="10">
              <el-form-item label="性别" prop="sex">
                <el-radio-group v-model="form.sex" >
                  <el-radio v-for="item in dict.type.sex" :key="item.value" :label="item.value" disabled>
                    {{ item.label }}
                  </el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="10">
              <el-form-item label="会员卡号" prop="userNo" v-if="form.userNo!== null && form.userNo!== ''">
                <el-input v-model="form.userNo" placeholder="请输入会员号" disabled/>
              </el-form-item>
            </el-col> 
            <el-col :span="10">
              <el-form-item label="车牌号" prop="carNo">
                <el-input v-model="form.carNo" placeholder="请输入车牌号" disabled/>
              </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="备注信息" prop="description">
                <el-input v-model="form.description" placeholder="请输入备注信息" disabled/>
              </el-form-item>
            </el-col>
        </el-row>
        <div style="margin-top: 1%; margin-left: 2%; margin-right: 10%;">
          <el-divider content-position="center" >会员卡券信息</el-divider>
        </div>

        <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="卡项名称" prop="couponId">
                <el-select v-model="form.userCoupon.id" placeholder="请选择" style="width: 100%" @change="setData">
                  <el-option
                    v-for="item in form.coupons"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
                    <span style="float: left" :span="11">{{ item.label }}</span>
                    <span style="float: right; color: #8492a6; font-size: 13px;display: none" :span="11">{{ item.value }}</span>
                  </el-option>
                </el-select>
                  <!-- <el-input v-model="form.userCoupon.name" placeholder="如:10次xxx卡" /> -->
              </el-form-item>
            </el-col>
        </el-row>

        <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="卡内余额（元）" prop="balance" v-if="form.userCoupon.type === 'P'">
                  <el-input v-model="form.balance" placeholder="请输消费金额" disabled />
              </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="卡内余额（元）" prop="balance" v-if="false">
                  <el-input v-model="form.userCoupon.balance" placeholder="请输消费金额" disabled />
              </el-form-item>
            </el-col>
        </el-row>
        <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="卡内余次（次）" prop="balance" v-if="form.userCoupon.type === 'T'">
                  <el-input v-model="form.userCoupon.balance" placeholder="请输消费次数" disabled/>
              </el-form-item>
            </el-col>
        </el-row>

        <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="消费金额（元）" prop="expenseMoney" v-if="form.userCoupon.type === 'P'">
                  <el-input v-model="form.expenseMoney" placeholder="请输消费金额" @input="handleInput"/>
              </el-form-item>
            </el-col>
        </el-row>

        <el-row :gutter="20">
            <el-col :span="20">
              <el-form-item label="消费次数（次）" prop="expenseMoney" v-if="form.userCoupon.type === 'T'">
                <div class="input-with-buttons" style="display: flex; align-items: center;">
                  <el-input v-model="form.expenseMoney" placeholder="请输消费次数" disabled/>
                  <el-button @click="increment" type="primary" size="mini">+</el-button>
                  <el-button @click="decrement" type="primary" size="mini">-</el-button>
                </div>
              </el-form-item>
            </el-col>
        </el-row>
        
        
        <!-- <el-form-item label="头像" prop="avatar">
          <el-input v-model="form.avatar" placeholder="请输入头像" />
        </el-form-item>
        <el-form-item label="分组id" prop="groupId">
          <el-input v-model="form.groupId" placeholder="请输入分组id" />
        </el-form-item>
        <el-form-item label="微信open_id" prop="openId">
          <el-input v-model="form.openId" placeholder="请输入微信open_id" />
        </el-form-item>
        <el-form-item label="证件号码" prop="idcard">
          <el-input v-model="form.idcard" placeholder="请输入证件号码" />
        </el-form-item>
        <el-form-item label="等级id" prop="gradeId">
          <el-input v-model="form.gradeId" placeholder="请输入等级id" />
        </el-form-item>
        <el-form-item label="会员开始时间" prop="startTime">
          <el-date-picker clearable
            v-model="form.startTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择会员开始时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="会员结束时间" prop="endTime">
          <el-date-picker clearable
            v-model="form.endTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择会员结束时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="余额" prop="balance">
          <el-input v-model="form.balance" placeholder="请输入余额" />
        </el-form-item>
        <el-form-item label="积分" prop="point">
          <el-input v-model="form.point" placeholder="请输入积分" />
        </el-form-item>
        <el-form-item label="来源渠道" prop="source">
          <el-input v-model="form.source" placeholder="请输入来源渠道" />
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入密码" />
        </el-form-item>
        <el-form-item label="salt" prop="salt">
          <el-input v-model="form.salt" placeholder="请输入salt" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入地址" />
        </el-form-item>
        <el-form-item label="所属商户id" prop="merchantId">
          <el-input v-model="form.merchantId" placeholder="请输入所属商户id" />
        </el-form-item>
        <el-form-item label="所属店铺id" prop="storeId">
          <el-input v-model="form.storeId" placeholder="请输入所属店铺id" />
        </el-form-item>
        <el-form-item label="是否员工" prop="isStaff">
          <el-input v-model="form.isStaff" placeholder="请输入是否员工" />
        </el-form-item>
        <el-form-item label="最后操作人" prop="operator">
          <el-input v-model="form.operator" placeholder="请输入最后操作人" />
        </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确定扣卡</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listMember, getMember, delMember, addMember, updateMember } from "@/api/backendApi/member";
import request from '@/utils/request';
import Decimal from "@/api/common/decimal.js";

export default {
  name: "Member",
  dicts: ['sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员个人信息表格数据
      memberList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      multiLineData: ["第一行数据1", "第二行数据", "第三行数据"],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        mobile: null,
        groupId: null,
        userNo: null,
        avatar: null,
        name: null,
        openId: null,
        idcard: null,
        gradeId: null,
        startTime: null,
        endTime: null,
        balance: null,
        point: null,
        sex: null,
        birthday: null,
        carNo: null,
        source: null,
        password: null,
        salt: null,
        address: null,
        merchantId: null,
        storeId: null,
        isStaff: null,
        status: null,
        description: null,
        operator: null
      },
      // 表单参数
      form: {
         userCoupon: {
          
        }
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        mobile: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3-9]\d{9}$/,
            message: '手机号码格式错误',
            trigger: 'blur'
          }
        ],
        expenseMoney: [
          { required: true, message: "消费金额/次数不能为空", trigger: "input" },
          { validator: this.validateUsername, trigger: 'input' },
          {
            pattern: /^(?!0\d)\d{1,7}(\.\d{1,2})?$/,
            message: '数字长度不超过7位，小数位数不超过2位,不可为负数',
            trigger: 'input'
          }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  // mounted() {
  //     this.list = this.states.map(item => {
  //       return { value: `value:${item}`, label: `label:${item}` };
  //     });
  //   },
  methods: {
    /** 储值卡根据充值金额和赠送金额计算可用金额 */
    async handleInput(value) {
      await this.$refs.form.validateField('expenseMoney');
    },
    async validateUsername(rule, value, callback) {
      if (!value) {
        callback();
        return;
      }
      try {
        // 假设调用后端接口进行验证，例如使用 axios 发送请求
        let url = 'backendApi/userCoupon/'+this.form.userCoupon.id
        const response = await request.get(url);
        this.form.userCoupon.balance = response.data.balance;
        console.log('ub1',this.form.userCoupon.balance)
        console.log('bb1',this.form.balance)
        if(this.form.userCoupon.type === 'P'){
            if(response.data.balance>this.form.expenseMoney){
              const num1 = this.form.userCoupon.balance ? new Decimal(this.form.userCoupon.balance): new Decimal(0);
              const num2 = this.form.expenseMoney ? new Decimal(this.form.expenseMoney): new Decimal(0);
              const result = num1.sub(num2).toNumber();

              this.form.userCoupon.balance = result
              //用于刷新赋值
              this.form.balance = result;
              callback();
            }else{
              callback(new Error('消费金额应小于卡内余额'));
            } 
        }
      } catch (error) {
        callback(new Error('验证过程中出现错误，请稍后重试2'));
      }
    },
    //点击+
    increment() {
      if(this.form.userCoupon.balance>0){
        this.form.expenseMoney++;
        this.form.userCoupon.balance--;
      }
    },
    //点击-
    decrement() {
      if (this.form.expenseMoney > 1) {
        this.form.expenseMoney--;
        this.form.userCoupon.balance++;
      }
    },
    //点击卡项名称设置卡类型用于控制消费金额类型显隐
     setData(ids){
      console.log("333ids",this.form.userCoupon.idss)
      
      // let url = 'backendApi/userCoupon/'+ids
      // const response = await request.get(url);
      // this.form.type = response.data.type;

      // this.form.type2 = String(response.data.type);
      //   // 使用 $nextTick 确保 DOM 更新
      //   this.$nextTick(() => {
      //     console.log('DOM 更新完成');
      //   });
      
  
        

// getUserCoupon(id).then(response => {
//   this.form.type='P'
//   })

      // getUserCoupon(id).then(response => {
      //   this.form.balance = response.data.balance;
      //   this.form.type = response.data.type;
      //   console.log(this.form.type )
      //   if(response.data.type === 'T'){
      //     this.form.type = "T";
      //     if(this.form.balance > 0){
      //       this.form.expenseMoney="1";
      //       this.form.balance--;
            
      //     }else{
      //       this.form.expenseMoney="0";
      //       this.form.balance="0";
            
      //     }
      //   }else{
      //     if(this.form.balance > 0){

      //       if(expenseMoney){

      //       }
      //       this.form.expenseMoney="1";
      //       this.form.balance--;
      //     }else{
      //       this.form.expenseMoney="0";
      //       this.form.balance="0";
      //     }
      //   }
      // })
      // let labelv = '';
      // for(let item of this.form.coupons){
      //   if(item.value === id){
      //     labelv=item.label
      //   }
      // }
      
      // if(labelv.includes("余额") && labelv.includes("元")){
      //   this.form.type='P'
      // }else{
      //   this.form.type='T';
      //   this.form.expenseMoney="1";
      // }
      
    },
    /** 查询会员个人信息列表 */
    getList() {
      this.loading = true;
      listMember(this.queryParams).then(response => {
        this.memberList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        mobile: null,
        groupId: null,
        userNo: null,
        avatar: null,
        name: null,
        openId: null,
        idcard: null,
        gradeId: null,
        startTime: null,
        endTime: null,
        balance: null,
        point: null,
        sex: null,
        birthday: null,
        carNo: null,
        source: null,
        password: null,
        salt: null,
        address: null,
        merchantId: null,
        storeId: null,
        isStaff: null,
        createTime: null,
        updateTime: null,
        status: null,
        description: null,
        operator: null,
        userCoupon: {
          
        }
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    // handleAdd() {
    //   this.reset();
    //   this.open = true;
    //   this.title = "添加会员个人信息";
    // },
    handleAdd() {
      this.$router.push('/backend/member/addmember')
      this.open = true;
      this.title = "修改会员个人信息";
    },
    /** 修改按钮操作 */
    async handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      let counponsv = [];
      // getMember(id).then(response => {
        let url = "backendApi/member/"+id;
        const response = await request.get(url);
        this.form = response.data;
        //设置该用户卡信息
        let sid='';
        for(let item of response.data.userCouponList){
          var coupon = {
          "value": null,
          "label": null
          }
          if(item.type === 'T'){
          coupon.label=item.name+" 【余"+item.balance+"次】";
          }else{
          coupon.label=item.name+" 【余额"+item.balance+"元】";
          }
          coupon.value=item.id;
          counponsv.push(coupon);
          sid=item.id;
        }
        this.form.coupons=counponsv;
        //默认选择项
        this.form.userCoupon={id:sid};

        let url2 = 'backendApi/userCoupon/'+sid
        const response2 = await request.get(url2);
        this.form.userCoupon.type = response2.data.type;
        this.form.userCoupon.balance = response2.data.balance;
        this.form.balance = response2.data.balance;
        console.log("ub2",this.form.userCoupon.balance)
        console.log("bb2",this.form.balance)
        console.log("tt",this.form.userCoupon.type)
        // this.form.balance = this.form.userCoupon.balance;
        if(this.form.userCoupon.type === 'T' && this.form.userCoupon.balance > 0){
            this.form.expenseMoney = '1';
            this.form.userCoupon.balance--; 
            this.form.balance = this.form.userCoupon.balance;
            console.log("ub3",this.form.userCoupon.balance)
            console.log("bb3",this.form.balance)
        }
        // 使用 $nextTick 确保 DOM 更新
        // this.$nextTick(() => {});
          this.open = true;
          this.title = "修改会员个人信息";
        // });
    },
    /** 提交按钮 */
    submitForm() {
      this.form.clogType='B';
      console.log("ub01",this.form.userCoupon.balance)
      console.log("bb01",this.form.balance)
      this.form.balance = this.form.userCoupon.balance;
      console.log("ub02",this.form.userCoupon.balance)
      console.log("bb02",this.form.balance)
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            console.log("tijiao",this.form.userCoupon.type)
            console.log("tj222",this.form.balance)
             console.log("tj222ub",this.form.userCoupon.balance)
            updateMember(this.form).then(response => {
              this.$modal.msgSuccess("扣卡成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMember(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除会员"' + row.name +" "+row.mobile+ '"的数据项？').then(function() {
        return delMember(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('backendApi/member/export', {
        ...this.queryParams
      }, `member_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<p id="descriptionText">这里详细说明了这个区域的用途、功能以及相关操作等信息，比如它是用来展示最新的产品推荐，点击可以查看更多详情等等。</p>